use BaseData.dta, clear

sort code_c code_s year
egen pair = group(code_c code_s)
drop if year<2009|year>2021 
drop if missing(GI_s, Digital_prop, Size, Age, Per_asset, Ratio, Lev, Tobin_Q)
global var "GI_s Digital_prop Size Age Per_asset Ratio Lev Tobin_Q"
foreach i in $var{
    winsor2 `i', replace cuts(0 95) 
}
xtset pair year
xtdes
gen Digital_c=100*Digital_prop
save Data1.dta, replace

*Description of the variables
use Data1.dta, clear
tabstat GI_s Digital_c Size Age Per_asset Ratio Lev Tobin_Q, stat(n mean sd min p50 max)

*Benchmark regression
global Controls "Size Age Per_asset Ratio Lev Tobin_Q " 
reghdfe GI_s Digital_c, a(pair year) vce(cluster pair) keepsingletons 
reghdfe GI_s Digital_c $Controls, a(pair year) vce(cluster pair) keepsingletons 

*Robustness test
use Data1.dta, clear
reghdfe GI_s Digital_IA $Controls, a(pair year) vce(cluster pair) keepsingletons 
reghdfe GI_prop Digital_c $Controls, a(pair year) vce(cluster pair) keepsingletons 
tab year, gen(time)
drop time1
pantob GI_s Digital_c $Controls time2-time12 pair 

*Endogeneity test
use Data1.dta, clear
xtivreg2 GI_s (Digital_c=Mean_Digital Bartik_IV) $Controls dyear*, fe cluster(pair) first  
*PSM
set seed 101011 
gen ranorder=runiform()
sort ranorder
psmatch2 dg_dum $Controls, kernel outcome (GI_s) ate ties logit common 
pstest $Controls, both
drop if _weight==. 
reghdfe GI_s Digital_c $Controls, a(pair year) vce(cluster pair) keepsingletons 


*Mechanism test1
use Data1.dta, clear
reghdfe GI_c Digital_c $Controls, a(pair year) vce(cluster pair) keepsingletons  
reghdfe GI_s GI_c $Controls, a(pair year) vce(cluster pair) keepsingletons  
*Mechanism test2
reghdfe Digital_s Digital_c $Controls, a(pair year) vce(cluster pair) keepsingletons 
reghdfe GI_s Digital_s $Controls, a(pair year) vce(cluster pair) keepsingletons 

*Heterogeneity analysis
use Data1.dta, clear
reghdfe GI_s Digital_c $Controls if pollute_s==1, a(pair year) vce(cluster pair) keepsingletons 
reghdfe GI_s Digital_c $Controls if pollute_s==0, a(pair year) vce(cluster pair) keepsingletons 

reghdfe GI_s Digital_c $Controls if competition_s==1, a(pair year) vce(cluster pair) keepsingletons 
reghdfe GI_s Digital_c $Controls if competition_s==0, a(pair year) vce(cluster pair) keepsingletons 

reghdfe GI_s Digital_c $Controls if tech_c==1, a(pair year) vce(cluster pair) keepsingletons 
reghdfe GI_s Digital_c $Controls if tech_c==0, a(pair year) vce(cluster pair) keepsingletons 

reghdfe GI_s Digital_c $Controls if scale_c==1, a(pair year) vce(cluster pair) keepsingletons 
reghdfe GI_s Digital_c $Controls if scale_c==0, a(pair year) vce(cluster pair) keepsingletons 

reghdfe GI_s Digital_c $Controls if ERI_c==1, a(pair year) vce(cluster pair) keepsingletons 
reghdfe GI_s Digital_c $Controls if ERI_c==0, a(pair year) vce(cluster pair) keepsingletons 


*Further analysis
use FurData.dta, clear
egen id=group(code)
xtset id year
global var "GI Digital Size Age Per_asset Ratio Lev Tobin_Q"
foreach i in $var{
    winsor2 `i', replace cuts(0 95) 
}
center Digital GI
gen greendg=c_Digital*c_GI
global Controls "GI Digital Size Age Per_asset Ratio Lev Tobin_Q"
reghdfe ESG1 greendg Digital GI $Controls, a(id year) vce(cluster id) keepsingletons 
reghdfe ESG2 greendg Digital GI $Controls, a(id year) vce(cluster id) keepsingletons 
